package cn.vivi.recyclercomp;

import java.util.List;

import cn.vivi.recyclercomp.adapter.RecyclerViewBaseAdapter;
import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;

/**
 * 最后一个item要在水平方向占满屏幕
 * 
 * @author Vivi Peng
 * @date 2015-06-25
 * 
 */
public class LastItemMatchParentSpanSizeLookup extends SpanSizeLookup {

	private RecyclerViewBaseAdapter mAdapter;


	public LastItemMatchParentSpanSizeLookup() {
	}


	@Override
	public int getSpanSize(int posi) {
		if (mAdapter != null && mAdapter.getItemCount() > 0) {
			int size = mAdapter.getItemCount();
			if ((size - 1) % 2 == 0 && posi == size - 1) {
				return 2;
			}

			if ((size - 1) % 2 == 1 && (posi == size - 1 || posi == size - 2)) {
				return 2;
			}
		}
		return 1;
	}


	public void setAdapter(RecyclerViewBaseAdapter adapter) {
		mAdapter = adapter;
	}

}
